package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.CatMessageSms;
import com.happy.cat.project.system.service.ICatMessageSmsService;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 短信Controller
 *
 * @author verne
 * @date 2020-08-07
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/catMessageSms" )
@Api("短信 API")
public class CatMessageSmsController extends BaseController {

    private final ICatMessageSmsService iCatMessageSmsService;

    /**
     * 查询短信列表
     */
    @ApiOperation(value = "查询短信列表",notes = "查询短信列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:catMessageSms:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatMessageSms catMessageSms)
    {
        startPage();
        LambdaQueryWrapper<CatMessageSms> lqw = new LambdaQueryWrapper<CatMessageSms>();
        if (StringUtils.isNotBlank(catMessageSms.getContent())){
            lqw.eq(CatMessageSms::getContent ,catMessageSms.getContent());
        }
        List<CatMessageSms> list = iCatMessageSmsService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出短信列表
     */
    @ApiOperation(value = "导出短信列表",notes = "导出短信列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catMessageSms:export')" )
    @Log(title = "短信" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(CatMessageSms catMessageSms) {
        LambdaQueryWrapper<CatMessageSms> lqw = new LambdaQueryWrapper<CatMessageSms>(catMessageSms);
        List<CatMessageSms> list = iCatMessageSmsService.list(lqw);
        ExcelUtil<CatMessageSms> util = new ExcelUtil<CatMessageSms>(CatMessageSms. class);
        return util.exportExcel(list, "catMessageSms" );
    }

    /**
     * 获取短信详细信息
     */
    @ApiOperation(value = "获取短信详细信息",notes = "获取短信详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catMessageSms:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCatMessageSmsService.getById(id));
    }

    /**
     * 新增短信
     */
    @ApiOperation(value = "新增短信",notes = "新增短信",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catMessageSms:add')" )
    @Log(title = "短信" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatMessageSms catMessageSms) {
        return toAjax(iCatMessageSmsService.save(catMessageSms) ? 1 : 0);
    }

    /**
     * 修改短信
     */
    @ApiOperation(value = "修改短信",notes = "修改短信",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catMessageSms:edit')" )
    @Log(title = "短信" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatMessageSms catMessageSms) {
        return toAjax(iCatMessageSmsService.updateById(catMessageSms) ? 1 : 0);
    }

    /**
     * 删除短信
     */
    @ApiOperation(value = "删除短信",notes = "删除短信",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catMessageSms:remove')" )
    @Log(title = "短信" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iCatMessageSmsService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
